package org.zkoss.zktc.core.widget;

import java.util.List;

import org.openqa.selenium.WebElement;

public interface Widget {

	
	
	public WidgetDriver getDriver();
	
	public String getGadgetId();
	
	/** 
	 * get the dom that this widget attached
	 * @return
	 */
	public WebElement getDom();
	
	/**
	 * get the real-dom that this widget attached, if there is not real-dom in this widget, it returns the attached dom.
	 * @return
	 */
	public WebElement getRealDom();

	/**
	 * get id (server id) of this widget
	 * @return
	 */
	public String getId();
	
	/**
	 * get dom id of this widget
	 * @return
	 */
	public String getUuid();
	
	/**
	 * get widget attribute, if will check if there is a get method then a attribute on the widget
	 * @param name attribute name
	 * @return 
	 */
	public Object getAttribute(String name);
	public void setAttribute(String name,Object val);
	
	public Widget getWidgetAttribute(String name);
	
	/** 
	 * call to a method of the client widget
	 * @param methodName method name
	 * @param parameters parameters
	 * @return the return value of the client method, return null if the value is not number,boolean or string.
	 */
	public Object call(String methodName,Object... parameters);
	
	
	public Widget getParent();
	/**
	 * get next n-th parent
	 * @param height
	 * @return
	 */
	public Widget getParent(int height);	
	public List<Widget> getChildren();
		
	public Widget getNextSibling();	
	public Widget getPreviousSibling();	
	public Widget getFirstChild();	
	public Widget getLastChild();
	public int getChildrenSize();
	public String getWidgetName();
	public String getClassName();
	public String getMold();
	
	/** return label if this widget has label attribute, or null */
	public String getLabel();
	
	/** return value if this widget has value attribute, or null */
	public Object getValue();
	
	/** return value if this widget has text attribute, or null */
	public String getText();
	
	public WebElement findElement(String selector);
	public WebElement findElement(String selector,long timeout);
	public List<WebElement> findElements(String selector);
	public List<WebElement> findElements(String selector,long timeout);
	
	public Widget findWidget(String selector);
	public Widget findWidget(String selector,long timeout);
	public List<Widget> findWidgets(String selector);
	public Widget findWidget(String selector,boolean strict);
	public Widget findWidget(String selector,boolean strict,long timeout);
	public List<Widget> findWidgets(String selector,boolean strict);
	public List<Widget> findWidgets(String selector,boolean strict,long timeout);
	
//	public Widget show();
//	public Widget show(int trip,long timeout);
//	public Widget hide();
//	public Widget hide(int trip,long timeout);
	
	/**
	 * click on the widget, default wait for 1 ajax trip
	 */
	public Widget click();
	public Widget click(int trip,long timeout);
	
	/**
	 * double click on the widget, default wait for 1 ajax trip
	 */
	public Widget dbclick();
	public Widget dbclick(int trip,long timeout);
	
	/**
	 * right on the widget, default wait for 1 ajax trip
	 */
	public Widget rclick();
	public Widget rclick(int trip,long timeout);
	
	/**
	 * press tab on the widget, default wait for 1 ajax trip
	 */
	public Widget tab();
	public Widget tab(int trip,long timeout);
	
	/**
	 * enter text on the widget, it will return immediately, will not wait any ajax trip
	 */
	public Widget keys(CharSequence text);
	public Widget keys(CharSequence text,int trip,long timeout);
	
	/**
	 * replace text on the widget, it will return immediately, will not wait any ajax trip
	 */
	public Widget replace(CharSequence text);
	public Widget replace(CharSequence text,int trip,long timeout);
	
	/**
	 * focus on the widget, default wait for 1 ajax trip
	 */
	public Widget focus();
	public Widget focus(int trip,long timeout);
//	public Widget focus(long focusimeout);
//	public Widget focus(long focusimeout, int trip,long timeout);
	
	
	/**
	 * clear text on the widget, it will return immediately, will not wait any ajax trip
	 */
	public Widget clear();
	public Widget clear(int trip,long timeout);
	
	
	/** try to reattach widget if the widget is still exist but the dom was changed to a new one **/
	public Widget reattach();
	
	public boolean isVisible();
	
	/** dump widget on client or testcase log **/
	public void dump(boolean client);
	
	/** dump widget dom on client or testcase */
	public void dumpDom(boolean client);
	
}
